<template>
	<view class="container">
		<view class="zhanwei"></view>
		<view class="money-header">
			<view class="money-title">
				<view>到账支付宝</view>
				<view>lllxxxqqqiii@163.com</view>
			</view>
			<view class="money-money">
				<text>￥</text>
				<input type="number" v-model="params.amount" @input="changeText($event)" placeholder="输入提现金额"/>
			</view>
			<view class="money-withdraw">
				可提现金额{{amount}}
			</view>
		</view>
		<view class="button-zhanwei"></view>
		<view class="money-botton">
			<button :disabled='!flag' :class="flag?'active':''" @click="submit_amount">提交申请</button>
		</view>
	</view>
</template>

<script>
	import apiorder from '../../common/api/order'
	export default {
		data() {
			return {
				wallets:{},
				params:{
					amount:'',
				},
				amount:0,
				flag:false,
			}
		},
		onShow(){
			this.withdraw_info()
		},
		methods: {
			
			//判断提现金额是否合法
			changeText(e){
				this.params.amount = parseInt(e.detail.value)
				if(this.params.amount<=this.wallets.amount){
					this.amount = parseInt(this.wallets.amount)-this.params.amount
					this.flag=true
				}else{
					this.flag=false
				}
				if(isNaN(this.params.amount)){
					this.amount = this.wallets.amount
				}
			},
			
			//提现数据
			withdraw_info(){
				apiorder.withdraw_info({}).then(res =>{
					if(res.code == 1){
						this.wallets=res.data
						this.amount = res.data.amount
					}
				}).catch(cateres =>{
					
				});
			},
			
			//提现数据
			submit_amount(){
				apiorder.apply_income(this.params).then(res =>{
					if(res.code == 1){
	　　　　　　　　　	uni.showToast({
	　　　　　　　　　　　		title: '提现申请已提交',
	　　　　　　　　　　		icon: 'none'
	　　　　　　　　　	})
						this.withdraw_info()
					}
				}).catch(cateres =>{
					
				});
				
			},
		}
	}
</script>

<style lang="scss">
	page{
		background-color:#F5F5F5;
	}
	.zhanwei{
		padding:10upx;
	}
	.money-header{
		padding:0 10upx;
		background-color:#FFFFFF;
		.money-title{
			display:flex;
			flex-direction: row;
			flex-wrap: wrap;
			padding:20upx 0;
			border-bottom:1upx solid #F5F5F5;
			view{
				width:50%;
			}
			view:last-child{
				text-align:right;
			}
		}
		.money-money{
			display:flex;
			flex-direction: row;
			flex-wrap: wrap;
			padding:20upx 0;
			font-size:50upx;
			text{
				height:80upx;
				line-height:80upx;
			}
			input{
				height:80upx;
				line-height:80upx;
			}			
		}
		.money-withdraw{
			padding:10upx 0;
			color:#CCCCCC;
		}
	}
	.button-zhanwei{
		height:60upx;
	}
	.money-botton{
		margin:0 auto;
		button{
			width:550upx;
			background-color:#CCCCCC;
			color:#FFFFFF;
			border-radius:40upx;
			border:none;
		}
		.active{
			background-color:#FF0000;
		}
	}
</style>
